/**
 * 
 */
package br.srv.full.geoProcessing.entities.localidades;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import br.srv.full.geoProcessing.entities.GPSPoint;
import br.srv.full.geoProcessing.entities.Limit;

/**
 * @author carlos.pinheiro
 * 
 */
@Entity
@Table(name = "Locale")
public class Locale implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6201658470280115015L;

	@SuppressWarnings("unused")
	@Id
	@Column(length = 2)
	private String acronym;

	@Column(length = 50)
	private String name;

	@Column(length = 300)
	private String description;

	@ManyToOne
	private LocaleType type;

	@Embedded
	private GPSPoint gPSPoint;

	@OneToMany
	private List<Limit> limits;

	@OneToMany
	private List<Region> regions;

	@ManyToOne
	private Locale locale;

	@OneToMany
	@JoinTable(joinColumns = @JoinColumn(name = "acronym", referencedColumnName = "acronym"), inverseJoinColumns = @JoinColumn(name = "acronymSubLocale", referencedColumnName = "acronym"))
	private List<Locale> subLocales;

	@OneToMany
	@JoinTable(name = "LocaleCanUseTypes", joinColumns = @JoinColumn(name = "acronym", referencedColumnName = "acronym"), inverseJoinColumns = @JoinColumn(name = "localeCanUseType", referencedColumnName = "acronym"))
	private List<LocaleType> canUseTypes;

	public Locale() {
	}

	public Locale(String p_acronym) {
		setAcronym(p_acronym);
	}

	/**
	 * @param p_acronym
	 */
	public Locale(String p_acronym, String p_nome) {
		setAcronym(p_acronym);
		setName(p_nome);
	}

	/**
	 * @param p_localeType
	 * @param p_string
	 * @param p_string2
	 */
	public Locale(LocaleType p_type, String p_acronym, String p_nome) {
		setType(p_type);
		setAcronym(p_acronym);
		setName(p_nome);
	}

	/**
	 * @return the acronym
	 */
	public String getAcronym() {
		return this.acronym;
	}

	/**
	 * @param p_acronym
	 *            the acronym to set
	 */
	public void setAcronym(String p_acronym) {
		this.acronym = p_acronym;
	}

	/**
	 * @return the nome
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @param p_nome
	 *            the nome to set
	 */
	public void setName(String p_nome) {
		this.name = p_nome;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return getType() + ": " + getAcronym() + ", " + getName();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object p_obj) {
		if (p_obj instanceof Locale) {
			Locale l_locale = (Locale) p_obj;
			return l_locale.getAcronym().equalsIgnoreCase(this.getAcronym());
		}
		return false;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param p_description
	 *            the description to set
	 */
	public void setDescription(String p_description) {
		description = p_description;
	}

	/**
	 * @return the gps
	 */
	public GPSPoint getGps() {
		return gPSPoint;
	}

	/**
	 * @param p_gPSPoint
	 *            the gps to set
	 */
	public void setGps(GPSPoint p_gPSPoint) {
		gPSPoint = p_gPSPoint;
	}

	/**
	 * @return the limits
	 */
	public List<Limit> getLimits() {
		return limits;
	}

	/**
	 * @param p_limits
	 *            the limits to set
	 */
	public void setLimits(List<Limit> p_limits) {
		limits = p_limits;
	}

	/**
	 * @return the regions
	 */
	public List<Region> getRegions() {
		return regions;
	}

	/**
	 * @param p_regions
	 *            the regions to set
	 */
	public void setRegions(List<Region> p_regions) {
		regions = p_regions;
	}

	/**
	 * @return the locales
	 */
	public Locale getLocales() {
		return locale;
	}

	/**
	 * @param p_locales
	 *            the locales to set
	 */
	public void setLocales(Locale p_locales) {
		locale = p_locales;
	}

	/**
	 * @return the subLocales
	 */
	public List<Locale> getSubLocales() {
		return subLocales;
	}

	/**
	 * @param p_subLocales
	 *            the subLocales to set
	 */
	public void setSubLocales(List<Locale> p_subLocales) {
		subLocales = p_subLocales;
	}

	/**
	 * @return the type
	 */
	public LocaleType getType() {
		return type;
	}

	/**
	 * @param p_type
	 *            the type to set
	 */
	public void setType(LocaleType p_type) {
		type = p_type;
	}

	/**
	 * @return the canUseTypes
	 */
	public List<LocaleType> getCanUseTypes() {
		if (canUseTypes == null) {
			canUseTypes = new ArrayList<LocaleType>();
		}
		return canUseTypes;
	}

	/**
	 * @param p_canUseTypes
	 *            the canUseTypes to set
	 */
	public void setCanUseTypes(List<LocaleType> p_canUseTypes) {
		canUseTypes = p_canUseTypes;
	}

}
